#pragma once

#include "ReadIsClassifiedObjectAction.h"

#include "Classifier.h"
#include "InputPin.h"
#include "OutputPin.h"

namespace uml {

const bool ReadIsClassifiedObjectAction::isDirect_default_ = false;
ReadIsClassifiedObjectAction::ReadIsClassifiedObjectAction(const QString& umlType)
    : Action(umlType) {}

void ReadIsClassifiedObjectAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Action::fromJson(json, errorList);
    classifier_ = JsonSerializable::create<Classifier>(json.value("classifier"), errorList);

    isDirect_ = json.value("isDirect").toBool(isDirect_default_);
    object_ = JsonSerializable::create<InputPin>(json.value("object"), errorList);

    result_ = JsonSerializable::create<OutputPin>(json.value("result"), errorList);

}

void ReadIsClassifiedObjectAction::toJson(QJsonObject& json) {
    Action::toJson(json);
    if (classifier_) {
        QJsonObject classifier_json;
        classifier_->toJson(classifier_json);
        json.insert("classifier", classifier_json);
    }
    if (isDirect_ != isDirect_default_) {
        json.insert("isDirect", isDirect_);
    }
    if (object_) {
        QJsonObject object_json;
        object_->toJson(object_json);
        json.insert("object", object_json);
    }
    if (result_) {
        QJsonObject result_json;
        result_->toJson(result_json);
        json.insert("result", result_json);
    }
}

/// <summary>
/// classifier getter
/// The Classifier against which the classification of the input object is tested.
/// </summary>
shared_ptr<Classifier> ReadIsClassifiedObjectAction::classifier() const {
    return classifier_;
}

/// <summary>
/// classifier setter
/// The Classifier against which the classification of the input object is tested.
/// </summary>
void ReadIsClassifiedObjectAction::setClassifier(shared_ptr<Classifier> value) {
    classifier_ = value;
}

/// <summary>
/// isDirect getter
/// Indicates whether the input object must be directly classified by the given
/// Classifier or whether it may also be an instance of a specialization of the
/// given Classifier.
/// </summary>
bool ReadIsClassifiedObjectAction::isDirect() const {
    return isDirect_;
}

/// <summary>
/// isDirect setter
/// Indicates whether the input object must be directly classified by the given
/// Classifier or whether it may also be an instance of a specialization of the
/// given Classifier.
/// </summary>
void ReadIsClassifiedObjectAction::setIsDirect(bool value) {
    isDirect_ = value;
}

/// <summary>
/// object getter
/// The InputPin that holds the object whose classification is to be tested.
/// </summary>
shared_ptr<InputPin> ReadIsClassifiedObjectAction::object() const {
    return object_;
}

/// <summary>
/// object setter
/// The InputPin that holds the object whose classification is to be tested.
/// </summary>
void ReadIsClassifiedObjectAction::setObject(shared_ptr<InputPin> value) {
    object_ = value;
}

/// <summary>
/// result getter
/// The OutputPin that holds the Boolean result of the test.
/// </summary>
shared_ptr<OutputPin> ReadIsClassifiedObjectAction::result() const {
    return result_;
}

/// <summary>
/// result setter
/// The OutputPin that holds the Boolean result of the test.
/// </summary>
void ReadIsClassifiedObjectAction::setResult(shared_ptr<OutputPin> value) {
    result_ = value;
}

} // namespace uml
